//logs.js
const util = require('../../../utils/util.js')
const { TomatoUrl } = require('../../../config/config.js')

Page({
  data: {
    logs: [],
    activeIndex:0,
    dayList:[],
    list:[],
    sum:[
      {
        title:'今日番茄个数',
        val:'0'
      },
      {
        title: '今日专注时长',
        val: '0分钟'
      },
      {
        title: '累计番茄个数',
        val: '0'
      },
      {
        title: '累计专注时长',
        val: '0分钟'
      }
    ],
    todayNum:'',
    todayLong:'',
    sumNum:'',
    sumLong:''
  },
  onLoad:function(){  
    let _this = this
    wx.request({
      url: TomatoUrl +'/listToday/'+wx.getStorageSync('userinfo').id,
      method: 'GET',
      success: function(res){
        let sumTomato = res.data.result
        let sumTime = 0
        for(let i=0; i<sumTomato.length; i++){
          sumTime += sumTomato[i].timeLong
        }
        _this.setData({
          'sum[0].val' : sumTomato.length,
          'sum[1].val' : sumTime + '分钟'
        })
      }
    })
    wx.request({
      url: TomatoUrl +'/list/'+wx.getStorageSync('userinfo').id,
      method: 'GET',
      success: function(res){
        let sumTomato = res.data.result
        let sumTime = 0
        for(let i=0; i<sumTomato.length; i++){
          sumTime += sumTomato[i].timeLong
        }
        _this.setData({       
          'sum[2].val' : sumTomato.length,
          'sum[3].val' : sumTime + '分钟'
        })
      }
    })




  }
})
